package com.example.a16478095zxl;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private EditText phone;
    private EditText password;
    private EditText addMoney;//输入的金额
    private EditText call;//电话
    private Button bt_confirm;
    private Button countOk;//输入金额确认
    private Button phoneOk;//输入电话确认
    private LinearLayout display;
    private TextView dis_num;
    private  TextView dis_leftMoney;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    public void initView(){
        phone = findViewById(R.id.phone);
        password = findViewById(R.id.password);
        display = findViewById(R.id.loginSuccess);
        bt_confirm = findViewById(R.id.confirm);
        dis_leftMoney= findViewById(R.id.dis_leftMoney);
        dis_num = findViewById(R.id.dis_num);
        addMoney = findViewById(R.id.addMoney);
        countOk = findViewById(R.id.countOk);
        call = findViewById(R.id.call);
        phoneOk = findViewById(R.id.phoneOk);
        bt_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String inputUserName = phone.getText().toString();
                String inputPwd = password.getText().toString();
                if(inputUserName.equals("123456")&&inputPwd.equals("11")){
                    display.setVisibility(View.VISIBLE);
                    dis_num.setText(inputUserName);
                }else{
                    Toast.makeText(MainActivity.this,"用户名或密码错误",Toast.LENGTH_SHORT).show();
                }
            }
        });
        countOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String money = addMoney.getText().toString();
               float add_money = Float.valueOf(money);
                String money1 = dis_leftMoney.getText().toString();
                float lt_Money = Float.valueOf(money1);
              float allMoney = add_money + lt_Money;
              String result = String.valueOf(allMoney);
                dis_leftMoney.setText(result);
                addMoney.setText(null);
            }
        });
       


    }

}
